# Contributor: Duncan Bellamy <dunk@denkimushi.com>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=vectorscan
pkgver=5.4.7
pkgrel=3
pkgdesc="High-performance regular expression matching library"
url="https://www.hyperscan.io"
arch="x86 x86_64 aarch64 ppc64le"  #requires SSSE3, Neon, or VSX
license="BSD-3-Clause"
makedepends="
	boost-dev
	chrpath
	clang
	cmake
	coreutils
	pcre-dev
	py3-breathe
	ragel
	samurai
	sed
	sqlite-dev
	"
subpackages="$pkgname-doc $pkgname-dev $pkgname-utils"
source="$pkgname-$pkgver.tar.gz::https://github.com/VectorCamp/vectorscan/archive/refs/tags/vectorscan/$pkgver.tar.gz
	no-march-native.patch
	"
builddir="$srcdir/$pkgname-$pkgname-$pkgver"
build() {
	export CC=clang
	export CXX=clang++
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DBUILD_STATIC_AND_SHARED=ON \
		-DFAT_RUNTIME=OFF \
		"$CMAKE_CROSSOPTS" .
	cmake --build build --target all dev-reference
}

check() {
	cd build
	./bin/unit-hyperscan
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install

	cd "$pkgdir"
	install -Dm644 "$builddir"/LICENSE usr/share/licenses/$pkgname/LICENSE
	mkdir -p usr/bin
	for _f in hsbench hscheck hscollider;
	do
		mv "$builddir"/build/bin/"$_f" usr/bin/
		chrpath -d usr/bin/"$_f"
	done
	mkdir -p usr/share/html
	mv "$builddir"/build/doc/dev-reference/html usr/share/html/"$pkgname"
}

utils() {
	amove usr/bin/hsbench usr/bin/hscheck usr/bin/hscollider
}

sha512sums="
cdc35c39046579798fe26bb930c342d1deb32e1cf5a453dd97f1c8299e10712a48b99ee08656d1721569ffeb3923f0305acfc2c2c704e5eba32ba39e81dd616e  vectorscan-5.4.7.tar.gz
1fa2f030eea20d74efb283de5b2385f4156c12fed3bd4d76bde8fc3bf6abe512c41e410e48de59b0bcac3935b4952b5c0ea491608d0ab206097b77e294518cc6  no-march-native.patch
"
